import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';

BuildContext _context;

class DrawerHome extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    _context = context;
    return Scaffold(
      appBar: _appBar, //顶部
      drawer: _drawer, //侧滑菜单
      body: Text('内容'),
    );
  }

  // 顶部
  AppBar _appBar = AppBar(
    // leading: IconButton(
    //   icon: Icon(Icons.menu),
    //   tooltip: 'Navigreation',
    //   onPressed: () => debugPrint('Navigreation button is pressed'),
    // ),
    title: Center(
      child: Text('导航'),
    ),
    actions: <Widget>[
      IconButton(
        icon: Icon(Icons.search),
        tooltip: 'Search',
        onPressed: () => debugPrint('Search button is pressed'),
      ),
      IconButton(
        icon: Icon(Icons.more_horiz),
        tooltip: 'More',
        onPressed: () => debugPrint('More button is pressed'),
      )
    ],
  );

  // 侧滑菜单
  Drawer _drawer = Drawer(
      child: ListView(
    padding: EdgeInsets.zero,
    children: <Widget>[
      UserAccountsDrawerHeader(
        accountName: Text(
          'chen.xu',
          style: TextStyle(
            fontWeight: FontWeight.bold,
          ),
        ),
        accountEmail: Text('chen.xu@gaiaworks.cn'),
        currentAccountPicture: CircleAvatar(
            // 头像
            backgroundImage: CachedNetworkImageProvider(
                'https://upload.jianshu.io/users/upload_avatars/16864693/85e9e502-e7e9-456e-8381-119c851c586f.jpg')),
        decoration: BoxDecoration(
            color: Colors.black12,
            image: DecorationImage(
              // 背景图片
              image: CachedNetworkImageProvider(
                  'http://www.chinadaily.com.cn/hqgj/images/2012fgztdx/attachement/jpg/site1/20120416/001ec95b71aa10f5d57701.jpg'),
              fit: BoxFit.cover,
              colorFilter: ColorFilter.mode(
                Colors.yellow.withOpacity(0.3),
                BlendMode.lighten,
              ),
            )),
      ),
      ListTile(
        title: Text('Messages', textAlign: TextAlign.right),
        trailing: Icon(Icons.message, color: Colors.black12, size: 22.0),
        onTap: () => Navigator.pop(_context),
      ),
      ListTile(
        title: Text('Favoriate', textAlign: TextAlign.right),
        trailing: Icon(Icons.favorite, color: Colors.black12, size: 22.0),
        onTap: () => Navigator.pop(_context),
      ),
      ListTile(
        title: Text('Settings', textAlign: TextAlign.right),
        trailing: Icon(Icons.settings, color: Colors.black12, size: 22.0),
        onTap: () => Navigator.pop(_context),
      ),
    ],
  ));
}
